(function(){
    _$(document).ready(function(){
        function App(){};
        function excludeSpecial(s) {
            // 去掉转义字符
            s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
            // 去掉特殊字符
            s = s.replace(/[\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/);
            return s;
        };
        App.prototype.ajaxFn=function(){

        };
        App.prototype.eventFn=function(){
            _$("#fb").click(function(){
                var title=_$("#title").val();
                var cnt=_$("#textcontent").val();
                if(excludeSpecial(title).length>25){
                    tip("标题大于25个字");
                }else if(excludeSpecial(title).length<1){
                    $("#title").focus();
                }else if(excludeSpecial(cnt).length<5){
                    $("#textcontent").focus();
                }else if(excludeSpecial(cnt).length>2000){
                    tip("内容大于2000个字");
                }else{
                    _$.ajax({
                        type: 'post',
                        url: '/addForumCnt',
                        data: {bid: bid,title:title,cnt:cnt},
                        async: false,
                        success: function (data) {
                            if(data.code==1){
                                tip("发布成功");
                                setTimeout(function(){
                                    location.href='/book/forum/'+bid;
                                },1000);
                            }
                        }
                    });
                }
            });
        };
        App.prototype.init=function(){
            //事件调用
            this.ajaxFn();
            this.eventFn();
        };
        //程序初始化
        new App().init();
    });
})();